package cn.edu.leetcode.其他;

public class 快乐数 {

    public static void main(String[] args) {
        System.out.println(isHappy(19));

    }

    public static boolean isHappy(int n) {
        for (int i = 0; i < 100; i++) {
            String string = n + "";
            int sum = 0;

            for (char c : string.toCharArray()) {
                sum += Integer.valueOf(c + "") * Integer.valueOf(c + "");
            }

            if (sum == 1) {
                return true;
            }

            n = sum;
        }

        return false;
    }
}
